import VueRouter from 'vue-router'
import Vue from 'vue'
import auth from '@/utils/auth'
const Login = () => import('@/views/login')
const Home = () => import('@/views/home')
const Welcome = () => import('@/views/welcome')
const notFound = () => import('@/views/404')
const article =() => import('@/views/article')
const Image =() => import('@/views/image')
const publish = ()=> import('@/views/publish')
const comment = ()=> import('@/views/comment')
const fans =() => import('@/views/fans')
const setting = ()=> import('@/views/setting')
Vue.use(VueRouter)

const router = new VueRouter({
    routes: [
        { path: '/login', component: Login },
        {
            path: '/',
            component: Home,
            children: [
                { path: '/', component: Welcome },
                {path:'/article',component:article},
                {path:'/picture',component:Image},
                {path:'/publish',component:publish},
                {path:'/comment',component:comment},
                {path:'/fans',component:fans},
                {path:'/setting',component:setting}

            ]
        },
        {path:'*',component:notFound}
    ]
})
router.beforeEach((to,from,next)=>{
    if(to.path !== '/login' && !auth.getUser().token) return next('/login')
    next()
})
export default router